package view.ui
{
	import control.manager.GSaveManager;
	import control.manager.RoleManager;
	
	import data.PlayerData;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.external.ExternalInterface;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.system.ApplicationDomain;
	import flash.system.Capabilities;
	import flash.text.TextField;
	import flash.utils.getDefinitionByName;
	
	/**
	 * 角色头像界面 
	 * @author leo
	 * 
	 */	
	public class UIRoleHead extends Sprite
	{
		private const NAME :String = "mainUI_roleHeadUI";
		
		public var btnSave :SimpleButton;
		public var roleHP :MovieClip;
		public var roleMP :MovieClip;
		public var txtLevel :TextField;
		public var txtName :TextField;
		public var btnRecharge :SimpleButton;
		public var btnGuan :SimpleButton;
		public var btnShou :SimpleButton;
		public var btnBBS :SimpleButton;
		public function UIRoleHead()
		{
			super();
			init();
		}
		
		private function init():void
		{
			if(ApplicationDomain.currentDomain.hasDefinition(NAME))
			{
				var cls :Class = getDefinitionByName(NAME) as Class;
				var mc :MovieClip = new cls() as MovieClip;
				addChild(mc);
				
				this.btnSave = mc.btnSave;
				this.btnGuan = mc.btnGuan;
				this.btnShou = mc.btnShou;
				this.btnBBS = mc.btnBBS;
				this.btnRecharge = mc.btnRecharge;
				
				this.roleHP = mc.UI_people.roleHP;
				this.roleMP = mc.UI_people.roleMP;
				this.txtLevel = mc.UI_people.txtLevel;
				this.txtName = mc.UI_people.txtName;
				
				addEventListener(MouseEvent.MOUSE_UP,mouseHandler);
			}
		}
		
		private function mouseHandler(event :MouseEvent):void
		{
			
			switch(event.target)
			{
				//官网，bbs,充值
				case this.btnBBS:
				case this.btnGuan:
				case this.btnRecharge:
					var url :String = "http://www.longsihao.com";
					if (Capabilities.playerType == 'ActiveX' && isJavascript) 
					{
						ExternalInterface.call("window.open", url);
					}
					else 
					{
						navigateToURL(new URLRequest(url),"_blank");
					}
					break;
				//保存
				case this.btnSave:
					var playerData :PlayerData = RoleManager.instance.playerData;
					GSaveManager.instance.savePlayerData(playerData);
					break;
				//收藏
				case this.btnShou:
					if(ExternalInterface.available)
					{
						ExternalInterface.call("");
					}else
					{
						trace("不是在网页上运行，不能收藏");
					}
					break;
			}
		}
		
		private function get isJavascript():Boolean
		{
			var str:String;
			try
			{
				str = ExternalInterface.call("function(){return location.href}");
			}catch(err:Error)
			{
				
			}
			return Boolean(str);
		}
	}
}